package com.xzq.server;

import com.xzq.codec.MessageCodec;
import com.xzq.codec.ProcotolFrameDecoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

/**
 * @Author xzq
 * @Description //TODO
 * @Date 2021/11/22 21:19
 * @Version 1.0.0
 **/
public class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {

    private ServerMessageHandler serverMessageHandler;


    public ServerChannelInitializer(ServerMessageHandler serverMessageHandler) {
        this.serverMessageHandler = serverMessageHandler;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        //半包粘包解码器
        socketChannel.pipeline().addLast(new ProcotolFrameDecoder());
        //消息编解码器
        socketChannel.pipeline().addLast(new MessageCodec());
        //消息处理器
        socketChannel.pipeline().addLast(serverMessageHandler);
    }
}
